/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao.reponse;

import dao.DaoAbstract;
import entities.questionnaire.Questionnaire;
import entities.reponse.AbstractReponse;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author aurelien.emery
 */
@Stateless
public class DaoAbstractReponse extends DaoAbstract<AbstractReponse> implements DaoAbstractReponseLocal {
    @PersistenceContext(unitName = "EJBProjetEFPPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public DaoAbstractReponse() {
        super(AbstractReponse.class);
    }

    @Override
    public long countAllByQuestionnaire(Questionnaire questionnaire) {
        try {
            Query q = em.createNamedQuery("AbstractReponse.countAllByQuestionnaire");
            q.setParameter("questionnaire", questionnaire);
            return (Long)q.getResultList().get(0);
        } catch (NoResultException noResutlExcep) {
            return 0;
        }
    }

}
